package com.freewater.springboot.demo.scopedbean;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import static org.springframework.web.context.WebApplicationContext.SCOPE_REQUEST;

@Configuration
public class AppConfig {

    @Bean
    public UserService userService() {
        return new UserService();
    }

    @Bean
    @Scope(SCOPE_REQUEST)
    public LoginAction loginAction(HttpServletRequest request) {
        return new LoginAction(request.getParameter("username"),
                request.getParameter("password"));
    }
}
